PHP This! A Beginners Guide to Learning Object Oriented PHP by Michelle Gosney
Author:Michelle Gosney [Gosney, Michelle]
Language: eng
Format: mobi
Tags: Reference
ISBN: 9781456615291
Publisher: eBookIt.com
Published: 2013-06-04T04:00:00+00:00
Now we need to build a model, called ShowModel, that corresponds to the controller above.
Model
As you can see below, the model that corresponds to the “Show” controller is defined in a class called ShowModel in a file named show.php that is in the models directory:
This is where we finally put our data model to use by creating some sub menu objects which extend the abstract Menu class. Recall that the abstract Menu class has a method called getAllMenuItems which creates MenuItem objects and loads them with relevant data from the menuitem table in the database. Also recall that we override this method in the DinnerMenu class.
Note that according to our business design, the LunchMenu and DinnerMenu will use the same MenuItems in our application because we employed interfaces that enforce this business rule. Remember that these interfaces are used for the purpose of adjusting the prices and serving sizes between lunch and dinner menus which both have the same menu items. As a result we override the getAllMenuItems($menuitemid) method of the abstract Menu class in the DinnerMenu class. Had we not designed our application this way we normally would have included the getAllMenuItems() method in the DBMapper class instead of including it in the base Menu class. We did it the way that we did in order to demonstrate the use of interfaces.
For starters, I am just going to add sub menus for drinks, appetizers, lunch and dinner by creating instances of the DrinkMenu, AppetizerMenu, LunchMenu and DinnerMenu classes respectively. Each of these objects will call the getAllMenuItems() method to retrieve relevant data which correlates to the const id of each object’s class. The $dinner object calls the getAllMenuItems() method that it overrides in order to implement the interfaces that are referenced by the DinnerMenu class. When you look at the output be sure to compare prices and serving sizes between matching menu items on the Lunch and Dinner Menus.
There is one last thing we have to do before all of this will work. We have to add references to the controllers/show.php and models/show.php files to the index.php file. The index.php file is the point of entry for URL requests and is also the assembly file that ties everything together. Our data model and helper files are all referenced here too. It also is where we create an instance of the Interpreter class and pass it the $_GET array that contains the query string values in the URL. The instance of the Interpreter class then creates the appropriate controller object based on the URL input. The last thing the index.php file does is invoke the ExecuteAction method of the controller object which in turn executes the action in the URL:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25283)
Hello! Python by Anthony Briggs(24336)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23429)
Kotlin in Action by Dmitry Jemerov(22507)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21969)
Dependency Injection in .NET by Mark Seemann(21838)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20707)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19521)
Grails in Action by Glen Smith Peter Ledbrook(18603)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17031)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15842)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13690)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11851)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11151)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10621)
Hit Refresh by Satya Nadella(9192)
The Kubernetes Operator Framework Book by Michael Dame(8566)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8400)
Robo-Advisor with Python by Aki Ranin(8360)